package com.study.mirrorforest.main.model.tags.controller;


import com.study.mirrorforest.main.common.response.R;
import com.study.mirrorforest.main.model.tags.dto.TagDTO;
import com.study.mirrorforest.main.model.tags.dto.TagsDTO;
import com.study.mirrorforest.main.model.tags.service.impl.TagsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/tags")
public class TagsController {

    @Autowired
    private TagsServiceImpl tagsService;

    @PostMapping("/create")
    public R createTag(@RequestBody TagDTO tag) {
        System.out.println("Received tag: " + tag);
        if(tag == null || tag.getName() == null || tag.getName().equals("")){
            return R.error(400, "标签名称不能为空");
        }
        return tagsService.CreateTag(tag.getName());
    }

    @GetMapping("/list")
    public R getTagsList() {
        return tagsService.GetTagsList();
    }

    @DeleteMapping("/delete/{id}")
    public R deleteTag(@PathVariable Integer id) {
        if(id == null || id <= 0){
            return R.error(400, "无效的标签ID");
        }
        return tagsService.DeleteTag(id);
    }



}
